package com.swu.pad.reflection.service.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.swu.pad.assignment.dao.AssignmentDao;
import com.swu.pad.assignment.dao.AssignmentPadDao;
import com.swu.pad.assignment.entity.Assignment;
import com.swu.pad.assignment.entity.AssignmentPad;
import com.swu.pad.course.dao.CourseGroupUserDao;
import com.swu.pad.course.entity.CourseGroupUser;
import com.swu.pad.reflection.dao.RftDimTipsDao;
import com.swu.pad.reflection.entity.RftDimTips;
import com.swu.pad.reflection.service.RftDimTipsService;;




@Service
@Transactional
public class RftDimTipsServiceImpl implements RftDimTipsService {
     
	@Autowired 
	private  RftDimTipsDao rftDimTipsDao;
	@Autowired 
	private  AssignmentPadDao aspDao;
	@Autowired 
	private  CourseGroupUserDao cguDao;
	@Autowired 
	private  AssignmentDao asmDao;
	
	/*
	 * 保存或者修改 反思维度
	 */
	@Override
	public RftDimTips saveRftDimTip(RftDimTips rftDimTips) {
		return rftDimTipsDao.saveAndFlush(rftDimTips);
	}
	
	/*
	 * 获取所有反思维度
	 */
	@Override
	public List<RftDimTips> getAllReflectionDims() {
		return rftDimTipsDao.findAll();
	}
   
	/*
	 * 获取某次作业下的反思维度
	 * (non-Javadoc)
	 * @see com.swu.pad.reflection.service.ReflectionTemplateService#getRftDimScore(java.lang.String, java.lang.String)
	 */
	@Override
	public Map<String,Object> getRftDimScore(String assignmentPadId) {
	    AssignmentPad assignmentPad=aspDao.findOne(assignmentPadId);
	    String[] apd=assignmentPadId.split("\\$");
	    String groupId=apd[0];
	    CourseGroupUser student=cguDao.findOneCourseGroupUserByGroupId(groupId);
	    String assignmentId=assignmentPad.getAssignmentId();
	    Assignment assignment=asmDao.findOne(assignmentId);
	    //不关联作业了 反思维度，关联模板了。作业-模板id-反思写作提示语维度（也用于打分）
	    List<RftDimTips> rftTs=rftDimTipsDao.findByTemplateId(assignment.getRftDimTipTptId());
	    Map<String, Object> res=new HashMap<String, Object>();
	    res.put("rftTs", rftTs);
	    res.put("student",student);
		return res;
	}

	

}
